Fix correlated EXISTS with constant-false predicate produces dangling mark column reference#22692
Open
xiedeyantu wants to merge 1 commit into
Open
Fix correlated EXISTS with constant-false predicate produces dangling mark column reference#22692xiedeyantu wants to merge 1 commit into
xiedeyantu wants to merge 1 commit into
Conversation
… mark column reference
Member
Author
|
@alamb Could you please check if this fix is correct? |
Member
Author
|
@neilconway Could you help me take a look? |
Contributor
|
Sorry @xiedeyantu -- I am not likely to have a lot of time to review SQL corner cases like this unless people are hitting them in production. I have too many other PRs to review at this time |
Contributor
|
@xiedeyantu FWIW, I'd still be interested in reviewing this, I just haven't had a chance to get round to it yet. |
Contributor
|
To be clear I didn't mean that this isn't a bug. I was trying to say that given how I prioritize reivews by my estimate of impact * time to review. I find reviewing corner case sql issues quite tricky to review carefully as it requires reasoning about the SQL semantics (which takes me a long time personally) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Queries with an embedded correlated
EXISTSpredicate can be decorrelated into aLeftMarkjoin. If the subquery side is later optimized toEmptyRelation,PropagateEmptyRelationcould replace the mark join with only the surviving input and drop the syntheticmarkcolumn. The parent filter still referenced that column, causing planning to fail with errors like:Schema error: No field named __correlated_sq_1.markWhat changes are included in this PR?
This PR updates
PropagateEmptyRelationhandling for mark joins:LeftMarkwith an empty right side now preserves left rows and projectsFALSE AS mark.RightMarkwith an empty left side now preserves right rows and projectsFALSE AS mark.Are these changes tested?
Yes.
Added optimizer unit coverage for
LeftMarkandRightMarkjoins with an empty opposite side.Added a sqllogictest regression for a correlated
EXISTSunderORwhere the subquery is optimized to empty by a constant-false predicate.Verified with:
Are there any user-facing changes?
Yes. Affected SQL queries now plan and execute correctly instead of failing with a schema error. No API changes.